package com.fmh.mybatisplus.controller;

import com.fmh.mybatisplus.comoon.vo.Result;
import com.fmh.mybatisplus.security.LoginSuccessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys")
public class SetPwdController {

    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;
    @Autowired
    LoginSuccessHandler loginSuccessHandler;

    @GetMapping("/setpwd")
    public Result setpwd(){
        // 加密后的密码
        String pwd = bCryptPasswordEncoder.encode("admin888");
        // 对比
        boolean matches = bCryptPasswordEncoder.matches("admin888", pwd);
        // 打印
        System.out.println("匹配结果：" + matches);
        // 返回
        return Result.success(pwd);
    }

    @PostMapping("/login")
    public Result login(
            @RequestParam("username") String username,
            @RequestParam("password") String password
    ) {
        // 获取当前登录用户的状态
        return Result.success(loginSuccessHandler);
    }

    @PostMapping("/logout")
    public Result logout() {
        return Result.success("ok");
    }

}
